from time import sleep

from selenium import webdriver
ff_driver = "C:/Python35-32/Scripts/geckodriver.exe"
ff_exe = "C:/Program Files (x86)/Mozilla Firefox/firefox.exe"
driver = webdriver.Firefox(firefox_binary=ff_exe,executable_path=ff_driver)
# 打开登录页面
driver.get('http://localhost/jxc/index.asp')
# 完成登录
ipts = driver.find_elements_by_tag_name('input')
ipts[0].send_keys('admin')
ipts[1].send_keys('admin')
ipts[2].click()

sleep(2)
# 从当前默认位置切换到菜单框架中
driver.switch_to.frame('left')
# 点击菜单 系统设置
sysset_css = '.menuall > tbody:nth-child(1) > tr:nth-child(13) > td:nth-child(1)'
driver.find_element_by_css_selector(sysset_css).click()
sleep(2)
# 继续点击：计量单位管理
danwei_css = '#g_6 > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(7) > td:nth-child(1)'
driver.find_element_by_css_selector(danwei_css).click()
sleep(2)
# 切换原始位置
driver.switch_to.default_content()
# 切到右侧框架
driver.switch_to.frame('right')
sleep(2)
# 点击添加单位按钮
bt_css = 'input.button:nth-child(1)'
driver.find_element_by_css_selector(bt_css).click()
sleep(2)
# 输入单位名称
driver.find_element_by_name('danwei').send_keys('吨')
# 点击确认按钮
driver.find_element_by_name('submit').click()
sleep(2)
# 处理弹框
driver.switch_to.alert.accept()
sleep(2)


# 切换原始位置
driver.switch_to.default_content()
# 从当前默认位置切换到菜单框架中
driver.switch_to.frame('left')
# 点击菜单 系统设置
sysset_css = '.menuall > tbody:nth-child(1) > tr:nth-child(13) > td:nth-child(1)'
driver.find_element_by_css_selector(sysset_css).click()
sleep(2)
# 继续点击：产品大类管理
bigclass_css = '#g_6 > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(5) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
driver.find_element_by_css_selector(bigclass_css).click()
sleep(2)
# 切换原始位置
driver.switch_to.default_content()
# 切到右侧框架
driver.switch_to.frame('right')
sleep(2)
# 点击添加大类按钮
bt_css = 'input.button:nth-child(1)'
driver.find_element_by_css_selector(bt_css).click()
sleep(2)
# 输入大类名称
driver.find_element_by_name('bigclass').send_keys('军用制式弹药')
# 点击确认按钮
driver.find_element_by_name('submit').click()
sleep(2)
# 处理弹框
driver.switch_to.alert.accept()
sleep(2)


# 切换原始位置
driver.switch_to.default_content()
# 从当前默认位置切换到菜单框架中
driver.switch_to.frame('left')
# 点击菜单 系统设置
sysset_css = '.menuall > tbody:nth-child(1) > tr:nth-child(13) > td:nth-child(1)'
driver.find_element_by_css_selector(sysset_css).click()
# 继续点击：产品小类管理
smallclass_css = '#g_6 > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(6) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
driver.find_element_by_css_selector(smallclass_css).click()
sleep(2)
# 切换原始位置
driver.switch_to.default_content()
# 切到右侧框架
driver.switch_to.frame('right')
sleep(2)
#请选择大类
bigclass_css = "body > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2) > select:nth-child(1) > option:nth-child(1)"
driver.find_element_by_css_selector(bigclass_css).click()
sleep(2)
# 点击添加小类按钮
bt_css = 'input.button:nth-child(1)'
driver.find_element_by_css_selector(bt_css).click()
sleep(2)
# 输入小类名称
driver.find_element_by_name('smallclass').send_keys('5.8毫米微声弹')
# 点击确认按钮
driver.find_element_by_name('submit').click()
sleep(2)
# 处理弹框
driver.switch_to.alert.accept()
sleep(2)

# 切换原始位置
driver.switch_to.default_content()
# 切换到顶部框架
driver.switch_to.frame('topFrame')
driver.find_element_by_link_text('安全退出').click()
sleep(2)
driver.switch_to.alert.accept()
sleep(2)
# 关闭浏览器
driver.quit()





